#include<iostream>
#include<unistd.h>
#include<sys/types.h>
#include<stdlib.h>
using namespace std;
int g_val = 100;
int main()
{
  pid_t id =fork();
  if(id == 0)
  {
    int cnt = 0;
    //child
    while(1)
    {
      cout << "i am child ,my pid" << getpid() << "my ppid:" << getppid() << "my g_val:" << g_val << "my &g_val" << &g_val << endl;
      if(cnt++ == 5)
      {
        g_val = 999;
      }
      sleep(1);
    }
  }
  else if(id < 0)
  {
    cout << "进程创建失败 " << endl;
    exit(1);
  }
  else
  {
    //father
    while(1)
    {
      cout << "i am father ,my pid" << getpid() << "my ppid:" << getppid() << "my g_val:" << g_val << "my &g_val" << &g_val << endl;
    sleep(1);
    }
  }
  return 0;
}
